<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>金豆明细</title>
    <link rel="stylesheet" href="${ctxPath}/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/admin.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/libs/zTree/css/zTreeStyle/zTreeStyle.css"/>
</head>

<body>
<% include("../layout/loading.html"){} %>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">
                <form>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键词:</label>
                            <div class="layui-input-block">
                                <input type="text" name="keyWords"  autocomplete="off" placeholder="搜索学员姓名/手机号" class="layui-input">
                            </div>
                        </div>
<!--                        <div class="layui-inline">-->
<!--                            <label class="layui-form-label">所属机构:</label>-->
<!--                            <div class="layui-input-block">-->
<!--                                <select name="organizationId">-->
<!--                                    <option value="">全部</option>-->
<!--                                    <% for(organization in organizationList) { %>-->
<!--                                    <option value="${organization.id}">${organization.organizationName}</option>-->
<!--                                    <% } %>-->
<!--                                </select>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="layui-inline">-->
<!--                            <label class="layui-form-label">所属校区:</label>-->
<!--                            <div class="layui-input-block">-->
<!--                                <select name="schoolId">-->
<!--                                    <option value="">全部</option>-->
<!--                                    <% for(school in schoolList) { %>-->
<!--                                    <option value="${school.id}">${school.schoolName}</option>-->
<!--                                    <% } %>-->
<!--                                </select>-->
<!--                            </div>-->
<!--                        </div>-->

<!--                        <div class="layui-inline">-->
<!--                            <label class="layui-form-label">所属班级:</label>-->
<!--                            <div class="layui-input-block">-->
<!--                                <select name="classId">-->
<!--                                    <option value="">全部</option>-->
<!--                                    <% for(classs in classList) { %>-->
<!--                                    <option value="${classs.id}">${classs.className}</option>-->
<!--                                    <% } %>-->
<!--                                </select>-->
<!--                            </div>-->
<!--                        </div>-->
                        <div class="layui-inline">
                            <div class="layui-form-item">
                                <label class="layui-form-label w-auto">所属机构:</label>
                                <div class="layui-input-inline">
                                    <select name="organizationId" id="organizationId"  lay-verType="tips"
                                            lay-filter="organization">
                                        <option value="">全部</option>
                                        <% for(organizations in organizationList) { %>
                                        <option value="${organizations.id}">${organizations.organizationName}</option>
                                        <% } %>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-item">
                                <label class="layui-form-label w-auto">所属校区:</label>
                                <div class="layui-input-inline">
                                    <select name="schoolId" id="schoolId" lay-verType="tips" lay-filter="school">
                                        <option value="">全部</option>
                                        <% for(school in schoolList) { %>
                                        <option value="${school.id}">${school.schoolName}</option>
                                        <% } %>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-item">
                                <label class="layui-form-label w-auto">所属班级:</label>

                                <div class="layui-input-inline">
                                    <select name="classId" id="classId">
                                        <option value="">全部</option>
                                        <% for(classs in classList) { %>
                                        <option value="${classs.id}">${classs.className}</option>
                                        <% } %>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button lay-submit=""  lay-filter="btnSearchSubmit" type="submit"  class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>查询</button>
                            <!--                        <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>查询</button>-->
                            <button id="btnReset" class="layui-btn icon-btn"><i class="layui-icon">&#xe669;</i>重置</button>
                        </div>
                    </div>
                </form>
            </div>

            <table class="layui-table" id="classsTable" lay-filter="classsTable"></table>
        </div>
    </div>
</div>



<!-- js部分 -->
<script type="text/javascript" src="${ctxPath}/assets/libs/jquery/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/libs/zTree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/js/common.js"></script>
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;

        // 渲染表格
        var insTb = table.render({
            elem: '#classsTable',
            url: '/admin/peaseRecord/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'},
                {field: 'childName', title: '学员姓名'},
                {field: 'schoolName', title: '所属校区'},
                {field: 'organizationName', title: '所属机构'},
                {field: 'className', title: '所属班级'},
                {field: 'telNo', title: '手机号'},
                {field: 'sourceNames', title: '行为'},
                // {field: 'peaseNum', title: '金豆变更'},
                {
                    field: 'peaseNum', title: '金豆变更', templet: function (d) {
                        if(d.source==10){
                            return d.peaseNum;
                        }else {
                            return '+'+d.peaseNum;
                        }
                    }
                },
                {field: 'createdDate', title: '时间'}
                // {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 200}
            ]]
        });

        //监听提交搜索
        form.on('submit(btnSearchSubmit)', function(data){
            var res=data.field;
            // console.log(res)
            insTb.reload({where: res,page:1});
            return false;
        });
        //选择机构后筛选所负责的校区
        form.on('select(organization)', function (data) {
            changeSchool();
        });

        form.on('select(school)', function (data) {
            changeClasss();
        });
        function changeSchool() {
            $("#schoolId").empty();
            $("#classId").empty();
            form.render("select");//重新渲染 固定写法
            var organizationId=$("#organizationId").val();
            if(organizationId!=null && organizationId!=""){
                $.ajax({
                    url: '/admin/school/getListByOrganizationId?organizationId='+ organizationId,
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        $('#schoolId').append(new Option("全部", ""));// 下拉菜单里添加元素
                        $('#classId').append(new Option("全部", ""));// 下拉菜单里添加元素
                        $.each(data, function (index, item) {
                            $('#schoolId').append(new Option(item.schoolName, item.id));// 下拉菜单里添加元素
                        });
                        form.render("select");//重新渲染 固定写法
                    }
                });
            }
        }

        function changeClasss() {
            $("#classId").empty();
            form.render("select");//重新渲染 固定写法
            var schoolId=$("#schoolId").val();
            if(schoolId!=null && schoolId!=""){
                $.ajax({
                    url: '/classs/getListBySchoolId?schoolId='+ schoolId,
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        $('#classId').append(new Option("全部", ""));// 下拉菜单里添加元素
                        $.each(data, function (index, item) {
                            $('#classId').append(new Option(item.className, item.id));// 下拉菜单里添加元素
                        });
                        form.render("select");//重新渲染 固定写法
                    }
                });
            }
        }

        // 重置
        $('#btnReset').click(function () {
            $('#edtSearch').val("");
            window.location.reload();
        });
    });
</script>
</body>
</html>